package com.lx.work2;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

/**
 * @author c先生
 * @date 2022年04月06日 下午 9:36:46
 * @describe
 */

public class StudentManager {
    public StudentManager() {
        init();
    }

    List<Student> list = new ArrayList<>();
    Scanner sc = new Scanner(System.in);

    //修改一名学生
    public Student updateStudent(String id){
        Iterator iterator = list.iterator();
        while (iterator.hasNext()){
            Student student = (Student) iterator.next();
            if(student.getStudentId().equals(id)){
                System.out.println("请输入姓名：");
                student.setStudentName(sc.next());
                System.out.println("请输入性别：");
                student.setSex(sc.next());
                return student;
            }
        }
        return null;
    }

    //删除一名学生
    public boolean deleteStudent(String id){
        Iterator iterator = list.iterator();
        while (iterator.hasNext()){
            Student student = (Student) iterator.next();
            if(student.getStudentId().equals(id)){
                iterator.remove();
                return true;
            }
        }
        return false;
    }

    //新增一名学生
    public boolean addStudent(Student student){
        boolean flag = list.add(student);
        return flag;
    }

    //查询所有学生
    public void showAllStudent(){
        for (Student student : list) {
            System.out.println(student.toString());
        }
    }

    //初始化
    public void init(){
        Student student1 = new Student("1001","李欣","男");
        Student student2 = new Student("1002","杨威","男");
        Student student3 = new Student("1003","周煜民","女");
        list.add(student1);
        list.add(student2);
        list.add(student3);
    }
}
